package com.qf.pojo;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义分页助手实体类
 * @author 千锋健哥
 */
public class PageHelper<E> {

    //当前页码
    private Integer currentPage;

    //每页显示条数
    private Integer pageSize = 5;

    //总页数
    private Integer totalPages;

    //总条数
    private Integer totalCounts;

    //起始行, 也就是从第几条开始查询
    private Integer startRows;

    //分页列表数据
    private List<E> list = new ArrayList<E>();

    /**
     * 构造方法
     * @return
     */
    public PageHelper(Integer currentPage) {
        //调用本类中两个参数的构造方法
        this(currentPage, 5);
    }

    /**
     * 构造方法
     * @return
     */
    public PageHelper(Integer currentPage, Integer pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        //计算从第几条开始查询
        this.setStartRows((currentPage - 1) * pageSize);
    }




    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }

    public Integer getTotalCounts() {
        return totalCounts;
    }

    //总条数的set方法
    public void setTotalCounts(Integer totalCounts) {
        this.totalCounts = totalCounts;
        //计算总页数
        this.setTotalPages(totalCounts % pageSize == 0 ? totalCounts/pageSize : totalCounts/pageSize+1);
    }

    public Integer getStartRows() {
        return startRows;
    }

    public void setStartRows(Integer startRows) {
        this.startRows = startRows;
    }

    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageHelper{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalPages=" + totalPages +
                ", totalCounts=" + totalCounts +
                ", startRows=" + startRows +
                ", list=" + list +
                '}';
    }

}
